package main

import (
	"flag"
	"fmt"
	"gcrontab/common"
	"gcrontab/master/api"
	"gcrontab/master/job"
	"runtime"
	"time"
)

var (
	confFile string
)

//解析命令行参数
func initArgs() {
	flag.StringVar(&confFile, "config", "../config/config.json", "指定master.json")
	flag.Parse()
}

//初始化线程
func initEnv() {
	runtime.GOMAXPROCS(runtime.NumCPU())
}

func main() {
	var err error

	//解析命名行参数
	initArgs()

	//初始化线程
	initEnv()

	//加载配置
	if err = common.InitConfig(confFile); err != nil {
		goto ERR
	}

	//初始化etcd
	if err = job.InitJob(); err != nil {
		goto ERR
	}

	//初始化Mongodb
	if err = job.InitLogManager(); err != nil {
		goto ERR
	}

	//初始化HTTP服务
	if err = api.InitApiServer(); err != nil {
		goto ERR
	}

	for {
		time.Sleep(1 * time.Second)
	}

ERR:
	fmt.Println("main shutdown:", err)

}
